{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find the Maximum Achievable Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: theMaximumAchievableX"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #找出最大的可达成数字"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个整数 <code>num</code> 和 <code>t</code> 。</p>\n",
    "\n",
    "<p>如果整数 <code>x</code> 可以在执行下述操作不超过 <code>t</code> 次的情况下变为与 <code>num</code> 相等，则称其为 <strong>可达成数字</strong> ：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>每次操作将 <code>x</code> 的值增加或减少 <code>1</code> ，同时可以选择将 <code>num</code> 的值增加或减少 <code>1</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回所有可达成数字中的最大值。可以证明至少存在一个可达成数字。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = 4, t = 1\n",
    "<strong>输出：</strong>6\n",
    "<strong>解释：</strong>最大可达成数字是 x = 6 ，执行下述操作可以使其等于 num ：\n",
    "- x 减少 1 ，同时 num 增加 1 。此时，x = 5 且 num = 5 。 \n",
    "可以证明不存在大于 6 的可达成数字。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = 3, t = 2\n",
    "<strong>输出：</strong>7\n",
    "<strong>解释：</strong>最大的可达成数字是 x = 7 ，执行下述操作可以使其等于 num ：\n",
    "- x 减少 1 ，同时 num 增加 1 。此时，x = 6 且 num = 4 。 \n",
    "- x 减少 1 ，同时 num 增加 1 。此时，x = 5 且 num = 5 。 \n",
    "可以证明不存在大于 7 的可达成数字。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= num, t&nbsp;&lt;= 50</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-the-maximum-achievable-number](https://leetcode.cn/problems/find-the-maximum-achievable-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-the-maximum-achievable-number](https://leetcode.cn/problems/find-the-maximum-achievable-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['4\\n1', '3\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def theMaximumAchievableX(self, num: int, t: int) -> int:\n",
    "        return num + 2 * t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def theMaximumAchievableX(self, num: int, t: int) -> int:\n",
    "        return num + t * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def theMaximumAchievableX(self, num: int, t: int) -> int:\n",
    "        for _ in range(t):\n",
    "            num += 2\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def theMaximumAchievableX(self, num: int, t: int) -> int:\n",
    "        return num + 2*t"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
